import '../public/index'
import url from '../data/url'
import request from '../data/request'
import {header} from '../data/config'

import {bank as valid_bank} from '../data/validate'

const base = url.base,
  addDeveloper = request.editDeveloperManage,
  getBankList = request.getBankList

// 页面标题
const title = '清算银行信息',
  action = '添加';

valid()

function valid() {

  let form_valid,
    $form = $('#form')

  $.validator.setDefaults({ // 只能放在validate规则配置之前
  })

  // 验证
  form_valid = $form.validate({
    errorPlacement: function (error, element) {
      error.appendTo(element.parents('.col-xs-24'))
    },
    rules: {
      bankCode: {
        required: true
      },
      name: {
        required: true
      },
      bankBranch: {
        required: true
      },
      clearBankCode: {
        required: true
      },
      upClearBankCode: {
        required: true
      }
    }
  })

}

$('#submit-form').on('click', () => {
  let formData = $('#form').serializeObject()
  $.ajax({
    headers: header,
    url: base + '/clearBankMappingInfo/v1/save.json',
    type: 'POST',
    data: formData
  }).then(res => {
    if (res.code == 0) {
      location.href = './index.html'
    }
  })
})
